import { ref } from "vue";
import { ElMessage, ElMessageBox } from "element-plus";
import deleteUserInfo from "@/service/main/system/deleteUser.js";
export default function pagemodelHooks(newCallback, editCallback) {
  const pageModalRef = ref(null);
  const defaultInfo = ref({});
  const handleNewData = (item) => {
    ElMessageBox.confirm("确定要删除这条信息吗?", "Warning", {
      confirmButtonText: "确定",
      cancelButtonText: "取消",
      type: "warning",
    })
      .then(async () => {
        const result = await deleteUserInfo("/updateUser", { id: item.id });
        console.log(result);
        if (result.data.code == 200 && result.status == 200) {
          ElMessage({
            type: "success",
            message: result.data.message,
          });
        } else {
          ElMessage.error(result.data.message);
        }
      })
      .catch(() => {
        ElMessage({
          type: "info",
          message: "删除取消",
        });
      });
  };
  const editbuttonClick = (item) => {
    defaultInfo.value = { ...item };
    if (pageModalRef.value) {
      pageModalRef.value.centerDialogVisible = true;
    }
    editCallback && editCallback();
    newCallback && newCallback();
  };
  const deletebuttonClick = (item) => {};
  return [
    pageModalRef,
    defaultInfo,
    editbuttonClick,
    handleNewData,
    deletebuttonClick,
  ];
}
